﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.sim {
    import Engine.Helpers.*;
    import flash.utils.*;
    import Classes.*;
    import Classes.actions.*;

    public class PickupManager implements IGameWorldStateObserver {

        private const MAILMAN_ACTION:Class;
        private const LUMBERJACK_ACTION:Class;
        private const FARMER_ACTION:Class;
        private const BUSINESS_ACTION:Class;

        private var m_world:GameWorld;
        private var m_numQueuedPickups:int;
        protected var m_pickupTypes:Dictionary;

        public function PickupManager(_arg1:GameWorld){
            this.MAILMAN_ACTION = ActionRentPickup;
            this.LUMBERJACK_ACTION = ActionClearWilderness;
            this.FARMER_ACTION = ActionCropHarvest;
            this.BUSINESS_ACTION = ActionBusinessPickup;
            super();
            this.m_world = _arg1;
            this.m_numQueuedPickups = 0;
            _arg1.addObserver(this);
        }
        public function initialize():void{
            var _local1:XML;
            var _local2:PickupType;
            this.m_pickupTypes = new Dictionary();
            this.m_numQueuedPickups = 0;
            for each (_local1 in Global.gameSettings.getPickupNpcs()) {
                _local2 = new PickupType(_local1);
                this.m_pickupTypes[_local2.type] = _local2;
            };
        }
        public function onGameLoaded(_arg1:Object):void{
        }
        public function onResourceChange(_arg1:MapResource, _arg2:Vector3, _arg3:Vector3):void{
        }
        public function cleanUp():void{
            this.m_pickupTypes = null;
            this.m_numQueuedPickups = 0;
        }
        public function enqueue(_arg1:String, _arg2:MapResource):void{
            var _local4:NPC;
            if (_arg2.isLocked()){
                return;
            };
            var _local3:Array = this.getQueue(_arg1);
            if (_local3){
                _local3.push(_arg2);
                this.m_numQueuedPickups++;
                _arg2.lock();
                _local4 = Global.world.citySim.npcManager.getPickupNPC(_arg1);
                if (_local4 == null){
                    Global.world.citySim.npcManager.createPickupNPC(_arg1, this.m_pickupTypes[_arg1].dummy);
                };
            };
        }
        public function dequeue(_arg1:String):MapResource{
            var _local2:Array = this.getQueue(_arg1);
            if (((_local2) && ((_local2.length > 0)))){
                this.m_numQueuedPickups--;
                return (this.getQueue(_arg1).shift());
            };
            return (null);
        }
        public function peek(_arg1:String):MapResource{
            var _local2:Array = this.getQueue(_arg1);
            return ((_local2) ? this.getQueue(_arg1)[0] : null);
        }
        public function addPickupAction(_arg1:NPC, _arg2:int=0, _arg3:MapResource=null, _arg4:Boolean=true):void{
            var _local5:PickupType = this.m_pickupTypes[_arg1.getItemName()];
            if (_local5){
                _arg1.getStateMachine().addState(new _local5.ActionDef(_arg1, _arg2, _arg3), _arg4);
            };
        }
        public function getQueue(_arg1:String):Array{
            if (this.m_pickupTypes[_arg1] != null){
                return (this.m_pickupTypes[_arg1].destinationQueue);
            };
            return (null);
        }
        public function clearQueue(_arg1:String):void{
            var _local3:MapResource;
            var _local4:Function;
            var _local2:Array = this.getQueue(_arg1);
            if (_local2){
                for each (_local3 in _local2) {
                    _local3.unlock();
                    _local4 = _local3.getProgressBarCancelFunction();
                    if (_local4 != null){
                        _local4();
                    };
                };
                this.m_numQueuedPickups = (this.m_numQueuedPickups - _local2.length);
                _local2.splice(0, _local2.length);
            };
            Global.world.citySim.npcManager.removePickupNPC(_arg1);
        }
        public function clearAllQueues():void{
            var _local1:PickupType;
            for each (_local1 in this.m_pickupTypes) {
                this.clearQueue(_local1.type);
            };
            this.m_numQueuedPickups = 0;
        }

    }
}//package Classes.sim 

import flash.utils.*;

class PickupType {

    public var type:String;
    public var dummy:Boolean;
    public var ActionDef:Class;
    public var destinationQueue:Array;

    public function PickupType(_arg1:XML){
        this.type = _arg1.@type;
        this.dummy = (_arg1.@dummy == "true");
        this.ActionDef = (getDefinitionByName(("Classes.actions." + _arg1.@action)) as Class);
        this.destinationQueue = new Array();
    }
}
